package com.ruoyi.project.monitor.warndistribute.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.monitor.warndistribute.domain.WarnDistribute;
import com.ruoyi.project.monitor.warndistribute.service.IWarnDistributeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 告警分发Controller
 * 
 * @author shixiangwen
 * @date 2020-04-09
 */
@Controller
@RequestMapping("/monitor/warndistribute")
public class WarnDistributeController extends BaseController
{
    private String prefix = "monitor/warndistribute";

    @Autowired
    private IWarnDistributeService warnDistributeService;

    @RequiresPermissions("monitor:warndistribute:view")
    @GetMapping()
    public String warndistribute()
    {
        return prefix + "/warndistribute";
    }

    /**
     * 查询告警分发列表
     */
    @RequiresPermissions("monitor:warndistribute:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WarnDistribute warnDistribute)
    {
        startPage();
        List<WarnDistribute> list = warnDistributeService.selectWarnDistributeList(warnDistribute);
        return getDataTable(list);
    }

    /**
     * 导出告警分发列表
     */
    @RequiresPermissions("monitor:warndistribute:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WarnDistribute warnDistribute)
    {
        List<WarnDistribute> list = warnDistributeService.selectWarnDistributeList(warnDistribute);
        ExcelUtil<WarnDistribute> util = new ExcelUtil<WarnDistribute>(WarnDistribute.class);
        return util.exportExcel(list, "warndistribute");
    }

    /**
     * 新增告警分发
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存告警分发
     */
    @RequiresPermissions("monitor:warndistribute:add")
    @Log(title = "告警分发", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WarnDistribute warnDistribute)
    {
        return toAjax(warnDistributeService.insertWarnDistribute(warnDistribute));
    }

    /**
     * 修改告警分发
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WarnDistribute warnDistribute = warnDistributeService.selectWarnDistributeById(id);
        mmap.put("warnDistribute", warnDistribute);
        return prefix + "/edit";
    }

    /**
     * 修改保存告警分发
     */
    @RequiresPermissions("monitor:warndistribute:edit")
    @Log(title = "告警分发", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WarnDistribute warnDistribute)
    {
        return toAjax(warnDistributeService.updateWarnDistribute(warnDistribute));
    }

    /**
     * 删除告警分发
     */
    @RequiresPermissions("monitor:warndistribute:remove")
    @Log(title = "告警分发", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(warnDistributeService.deleteWarnDistributeByIds(ids));
    }
}
